import os

from flask import Flask

def create_app():
    app = Flask(
        __name__,
        template_folder='../template',
        static_folder="../resource",
        static_url_path="/",)
    init_blueprint(app)
    app.config['SECRET_KEY'] = os.urandom(24)
    app.config['UPLOAD_FOLDER'] = 'resource/uploads'
    app.config['MAX_CONTENT_LENGTH'] = 10 * 1024 * 1024  # 10MB
    app.config['SECRET_KEY'] = 'your-secret-key-here'
    return app

def init_blueprint(app):
    from controller.user import user
    app.register_blueprint(user)

    # index 蓝图注册
    from controller.index import index
    app.register_blueprint(index)

    # 新增详情页蓝图注册
    from controller.detail import detail
    app.register_blueprint(detail)

    from controller.add_article import add_article
    app.register_blueprint(add_article)

    from controller.ai_controller import ai
    app.register_blueprint(ai)
